package presentation;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Banner
 */
@WebServlet("/Banner")
public class Banner extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Banner() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		/*response.setContentType("text/html");
		
		out.print("<html>");
		out.print("<head>");
		out.print("<title>Derpizza</title>");
		out.print("</head>");
		out.print("<body>");*/
		out.print("<div id=\"banner\">");
		out.print("<img src=\"/Derpizza/img/derpina.jpg\"/>");
		if(request.getSession().getAttribute("nomUser")==null){
			out.print("<p>Bienvenue, nous sommes le "+new SimpleDateFormat().format(new Date())+"</p>");
			out.print("<br/><a href=\"/Derpizza/connexion.jsp\">Se Connecter</a>");
		}else {
			out.print("<p>Bienvenue, "
					+(String)request.getSession().getAttribute("nomUser")+
					" nous sommes le "+new SimpleDateFormat().format(new Date())+"</p>");	
			out.print("<br/><a href=\"/Derpizza/SeDeconnecter\">Se Deconnecter</a>");		
		}
		out.print("</div>");
		//out.print("<div id=\"body\">");	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
